package cloud.maque.blog.controller;


import cloud.maque.blog.entity.MqComment;
import cloud.maque.blog.service.MqCommentService;
import cloud.maque.common.core.request.PageRequest;
import cloud.maque.common.core.response.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 评论表;(mq_comment)表控制层
 *
 * @author : maque.cloud
 * @date : 2025-2-6
 */
@Tag(name = "评论表对象功能接口")
@RestController
@RequestMapping("/mqComment")
public class MqCommentController {
    @Autowired
    private MqCommentService mqCommentService;

    /**
     * 通过ID查询单条数据
     * @param commentId 主键
     * @return 实例对象
     */
    @Operation(summary = "通过ID查询单条数据")
    @GetMapping("/detail/{commentId}")
    public R<MqComment> queryById(@PathVariable(value = "commentId") String commentId) {
        return R.ok("ok", mqCommentService.queryById(commentId));
    }

    /**
     * 分页查询
     *
     * @param pageReq 筛选条件
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("/list")
    public R<List<MqComment>> paginQuery(@RequestBody PageRequest<MqComment> pageReq) {
        //1.分页参数
        long current = pageReq.getPageIndex();
        long size = pageReq.getPageSize();
        //2.分页查询
        /*把Mybatis的分页对象做封装转换，MP的分页对象上有一些SQL敏感信息，还是通过spring的分页模型来封装数据吧*/
        IPage<MqComment> pageResult = mqCommentService.paginQuery(pageReq.getData(), current, size);
        return R.ok("OK", pageResult);
    }

    /**
     * 新增数据
     *
     * @param mqComment 实例对象
     * @return 实例对象
     */
    @Operation(summary = "新增数据")
    @PostMapping("/save")
    public R<MqComment> save(@RequestBody MqComment mqComment) {
        return R.ok("ok", mqCommentService.Save(mqComment));
    }

    /**
     * 通过主键删除数据
     *
     * @param commentId 主键
     * @return 是否成功
     */
    @Operation(summary = "通过主键删除数据")
    @DeleteMapping("/delete/{categoryId}")
    public R<Boolean> deleteById(@PathVariable("commentId") String commentId) {
        return R.ok("ok", mqCommentService.deleteById(commentId));
    }
}